var app = angular.module('myApp02', []);
app.controller('DRController02', function ($scope) {

  $scope.resultList = [{
    name: '演示地址#电容器-',
    valueU: '320.0',
    level: 'normal',
    valueP: '28.9',
    valueI: '18.5',
    valueQ: '17.2',
    valueCOS: '0.707'
  }, {
    name: '演示地址#电容器-',
    valueU: '320.0',
    level: 'danger',
    valueP: '67.2',
    valueI: '55.0',
    valueQ: '17.2',
    valueCOS: '0.707'
  }, {
    name: '演示地址#电容器-',
    valueU: '320.0',
    level: 'normal',
    valueP: '67.2',
    valueI: '55.0',
    valueQ: '17.2',
    valueCOS: '0.707'
  }, {
    name: '演示地址#电容器-',
    valueU: '320.0',
    level: 'normal',
    valueP: '67.2',
    valueI: '55.0',
    valueQ: '17.2',
    valueCOS: '0.707'
  }, {
    name: '演示地址#电容器-',
    valueU: '320.0',
    level: 'danger',
    valueP: '67.2',
    valueI: '55.0',
    valueQ: '17.2',
    valueCOS: '0.707'
  }, {
    name: '演示地址#电容器-',
    valueU: '320.0',
    level: 'normal',
    valueP: '67.2',
    valueI: '55.0',
    valueQ: '17.2',
    valueCOS: '0.707'
  }, {
    name: '演示地址#电容器-',
    valueU: '320.0',
    level: 'normal',
    valueP: '67.2',
    valueI: '55.0',
    valueQ: '17.2',
    valueCOS: '0.707'
  }, {
    name: '演示地址#电容器-',
    valueU: '320.0',
    level: 'normal',
    valueP: '67.2',
    valueI: '55.0',
    valueQ: '17.2',
    valueCOS: '0.707'
  }];

  setInterval(function () {
    $scope.$apply(
      mockData()
    );
  }, 500);

  //模拟数据变化
  function mockData() {
    angular.forEach($scope.resultList, function (data) {
      data.valueP = (Number(data.valueP) + Math.random() * 4).toFixed(2);
      data.valueI = (Number(data.valueI) + Math.random() * 3).toFixed(2);
      data.valueQ = (Number(data.valueQ) + Math.random() * 2).toFixed(2);
      data.valueCOS = (Number(data.valueCOS) + Math.random() * 1).toFixed(3);
      if (data.valueU > 360) {
        data.valueU = (Number(data.valueU) - Math.random() * 5).toFixed(2);
        data.level = 'danger';
      } else {
        data.valueU = (Number(data.valueU) + Math.random() * 5).toFixed(2);
        data.level = 'normal';
      }
    });
  }

});